package org.xmldap.xml;

import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.List;

import junit.framework.TestCase;
import nu.xom.Document;
import nu.xom.Element;

import org.json.JSONObject;
import org.xmldap.infocard.InfoCard;
import org.xmldap.infocard.TokenServiceReference;
import org.xmldap.infocard.UserCredential;
import org.xmldap.infocard.policy.SupportedClaim;
import org.xmldap.infocard.policy.SupportedClaimTypeList;
import org.xmldap.infocard.policy.SupportedToken;
import org.xmldap.infocard.policy.SupportedTokenList;
import org.xmldap.util.XmldapCertsAndKeys;
import org.xmldap.ws.WSConstants;
import org.xmldap.xmldsig.ValidatingEnvelopedSignature;


public class XmlUtilsTest extends TestCase {
  public void setUp() throws Exception {
    super.setUp();
  }

  public void testSimpleToJSON() throws Exception {
    Document doc = XmlUtils.parse("<root><a>root</a></root>");
    Element elt = doc.getRootElement();
    JSONObject json = XmlUtils.toJSON(elt);
    String expected = "{\"QualifiedName\":\"root\",\"Children\":[{\"QualifiedName\":\"a\",\"Children\":[\"root\"],\"LocalName\":\"a\"}],\"LocalName\":\"root\"}";
    assertEquals(expected, json.toString());
  }
  public void testNamespaceToJSON() throws Exception {
    Document doc = XmlUtils.parse("<RNS:root xmlns:RNS=\"urn:rns\"><ANS:a xmlns:ANS=\"urn:ans\">root</ANS:a></RNS:root>");
    Element elt = doc.getRootElement();
    JSONObject json = XmlUtils.toJSON(elt);
    String expected = "{\"NamespaceDeclarations\":[[\"RNS\",\"urn:rns\"]],\"NamespacePrefix\":\"RNS\",\"QualifiedName\":\"RNS:root\",\"NamespaceURI\":\"urn:rns\",\"Children\":[{\"NamespaceDeclarations\":[[\"ANS\",\"urn:ans\"]],\"NamespacePrefix\":\"ANS\",\"QualifiedName\":\"ANS:a\",\"NamespaceURI\":\"urn:ans\",\"Children\":[\"root\"],\"LocalName\":\"a\"}],\"LocalName\":\"root\"}";
    assertEquals(expected, json.toString());
  }
  
  public void testInfocardToJSON() throws Exception {
    InfoCard card = new InfoCard();
    card.setCardId("card1", 1);
    card.setIssuer("issuer");
    card.setTimeIssued("2006-09-28T12:58:26Z");
    {
      String displayName = "displayName";
      String uri = "uri";
      String description = "description";
      SupportedClaim claim = new SupportedClaim(displayName, uri, description);
      ArrayList<SupportedClaim> cl = new ArrayList<SupportedClaim>();
      cl.add(claim);
      SupportedClaimTypeList claimList = new SupportedClaimTypeList(cl);
      card.setClaimList(claimList);
    }
    {
      SupportedToken token = new SupportedToken(WSConstants.SAML11_NAMESPACE); // default is SAML11
      List<SupportedToken> list = new ArrayList<SupportedToken>();
      list.add(token);
      SupportedTokenList tokenList = new SupportedTokenList(list);
      card.setTokenList(tokenList);
    }
    {
      X509Certificate cert = XmldapCertsAndKeys.getXmldapCert1();
      UserCredential usercredential = new UserCredential(UserCredential.USERNAME, "username");
      TokenServiceReference tsr = new TokenServiceReference("sts", "mex", cert, usercredential);
      List<TokenServiceReference> tokenServiceReference = new ArrayList<TokenServiceReference>();
      tokenServiceReference.add(tsr);
      card.setTokenServiceReference(tokenServiceReference);
    }
    card.setPrivacyPolicy("privacyPolicyUrl", 1);

    JSONObject json = XmlUtils.toJSON(card.serialize());
    String expected = "{\"NamespaceDeclarations\":[[\"ds\",\"http://www.w3.org/2000/09/xmldsig#\"],[\"ic\",\"http://schemas.xmlsoap.org/ws/2005/05/identity\"],[\"mex\",\"http://schemas.xmlsoap.org/ws/2004/09/mex\"],[\"wsa\",\"http://www.w3.org/2005/08/addressing\"],[\"wsid\",\"http://schemas.xmlsoap.org/ws/2006/02/addressingidentity\"],[\"wst\",\"http://schemas.xmlsoap.org/ws/2005/02/trust\"]],\"NamespacePrefix\":\"ic\",\"Attributes\":[{\"NamespacePrefix\":\"xml\",\"Value\":\"en-us\",\"QualifiedName\":\"xml:lang\",\"NamespaceURI\":\"http://www.w3.org/XML/1998/namespace\",\"LocalName\":\"lang\"}],\"QualifiedName\":\"ic:InformationCard\",\"NamespaceURI\":\"http://schemas.xmlsoap.org/ws/2005/05/identity\",\"Children\":[{\"NamespaceDeclarations\":[[\"ic\",\"http://schemas.xmlsoap.org/ws/2005/05/identity\"]],\"NamespacePrefix\":\"ic\",\"QualifiedName\":\"ic:InformationCardReference\",\"NamespaceURI\":\"http://schemas.xmlsoap.org/ws/2005/05/identity\",\"Children\":[{\"NamespaceDeclarations\":[[\"ic\",\"http://schemas.xmlsoap.org/ws/2005/05/identity\"]],\"NamespacePrefix\":\"ic\",\"QualifiedName\":\"ic:CardId\",\"NamespaceURI\":\"http://schemas.xmlsoap.org/ws/2005/05/identity\",\"Children\":[\"card1\"],\"LocalName\":\"CardId\"},{\"NamespaceDeclarations\":[[\"ic\",\"http://schemas.xmlsoap.org/ws/2005/05/identity\"]],\"NamespacePrefix\":\"ic\",\"QualifiedName\":\"ic:CardVersion\",\"NamespaceURI\":\"http://schemas.xmlsoap.org/ws/2005/05/identity\",\"Children\":[\"1\"],\"LocalName\":\"CardVersion\"}],\"LocalName\":\"InformationCardReference\"},{\"NamespaceDeclarations\":[[\"ic\",\"http://schemas.xmlsoap.org/ws/2005/05/identity\"]],\"NamespacePrefix\":\"ic\",\"QualifiedName\":\"ic:Issuer\",\"NamespaceURI\":\"http://schemas.xmlsoap.org/ws/2005/05/identity\",\"Children\":[\"issuer\"],\"LocalName\":\"Issuer\"},{\"NamespaceDeclarations\":[[\"ic\",\"http://schemas.xmlsoap.org/ws/2005/05/identity\"]],\"NamespacePrefix\":\"ic\",\"QualifiedName\":\"ic:TimeIssued\",\"NamespaceURI\":\"http://schemas.xmlsoap.org/ws/2005/05/identity\",\"Children\":[\"2006-09-28T12:58:26Z\"],\"LocalName\":\"TimeIssued\"},{\"NamespaceDeclarations\":[[\"ic\",\"http://schemas.xmlsoap.org/ws/2005/05/identity\"]],\"NamespacePrefix\":\"ic\",\"QualifiedName\":\"ic:TokenServiceList\",\"NamespaceURI\":\"http://schemas.xmlsoap.org/ws/2005/05/identity\",\"Children\":[{\"NamespaceDeclarations\":[[\"ic\",\"http://schemas.xmlsoap.org/ws/2005/05/identity\"]],\"NamespacePrefix\":\"ic\",\"QualifiedName\":\"ic:TokenService\",\"NamespaceURI\":\"http://schemas.xmlsoap.org/ws/2005/05/identity\",\"Children\":[{\"NamespaceDeclarations\":[[\"wsa\",\"http://www.w3.org/2005/08/addressing\"]],\"NamespacePrefix\":\"wsa\",\"QualifiedName\":\"wsa:EndpointReference\",\"NamespaceURI\":\"http://www.w3.org/2005/08/addressing\",\"Children\":[{\"NamespaceDeclarations\":[[\"wsa\",\"http://www.w3.org/2005/08/addressing\"]],\"NamespacePrefix\":\"wsa\",\"QualifiedName\":\"wsa:Address\",\"NamespaceURI\":\"http://www.w3.org/2005/08/addressing\",\"Children\":[\"sts\"],\"LocalName\":\"Address\"},{\"NamespaceDeclarations\":[[\"wsa\",\"http://www.w3.org/2005/08/addressing\"]],\"NamespacePrefix\":\"wsa\",\"QualifiedName\":\"wsa:Metadata\",\"NamespaceURI\":\"http://www.w3.org/2005/08/addressing\",\"Children\":[{\"NamespaceDeclarations\":[[\"mex\",\"http://schemas.xmlsoap.org/ws/2004/09/mex\"]],\"NamespacePrefix\":\"mex\",\"QualifiedName\":\"mex:Metadata\",\"NamespaceURI\":\"http://schemas.xmlsoap.org/ws/2004/09/mex\",\"Children\":[{\"NamespaceDeclarations\":[[\"mex\",\"http://schemas.xmlsoap.org/ws/2004/09/mex\"]],\"NamespacePrefix\":\"mex\",\"QualifiedName\":\"mex:MetadataSection\",\"NamespaceURI\":\"http://schemas.xmlsoap.org/ws/2004/09/mex\",\"Children\":[{\"NamespaceDeclarations\":[[\"mex\",\"http://schemas.xmlsoap.org/ws/2004/09/mex\"]],\"NamespacePrefix\":\"mex\",\"QualifiedName\":\"mex:MetadataReference\",\"NamespaceURI\":\"http://schemas.xmlsoap.org/ws/2004/09/mex\",\"Children\":[{\"NamespaceDeclarations\":[[\"wsa\",\"http://www.w3.org/2005/08/addressing\"]],\"NamespacePrefix\":\"wsa\",\"QualifiedName\":\"wsa:Address\",\"NamespaceURI\":\"http://www.w3.org/2005/08/addressing\",\"Children\":[\"mex\"],\"LocalName\":\"Address\"}],\"LocalName\":\"MetadataReference\"}],\"LocalName\":\"MetadataSection\"}],\"LocalName\":\"Metadata\"}],\"LocalName\":\"Metadata\"},{\"NamespaceDeclarations\":[[\"wsid\",\"http://schemas.xmlsoap.org/ws/2006/02/addressingidentity\"]],\"NamespacePrefix\":\"wsid\",\"QualifiedName\":\"wsid:Identity\",\"NamespaceURI\":\"http://schemas.xmlsoap.org/ws/2006/02/addressingidentity\",\"Children\":[{\"NamespaceDeclarations\":[[\"ds\",\"http://www.w3.org/2000/09/xmldsig#\"]],\"NamespacePrefix\":\"ds\",\"QualifiedName\":\"ds:KeyInfo\",\"NamespaceURI\":\"http://www.w3.org/2000/09/xmldsig#\",\"Children\":[{\"NamespaceDeclarations\":[[\"ds\",\"http://www.w3.org/2000/09/xmldsig#\"]],\"NamespacePrefix\":\"ds\",\"QualifiedName\":\"ds:X509Data\",\"NamespaceURI\":\"http://www.w3.org/2000/09/xmldsig#\",\"Children\":[{\"NamespaceDeclarations\":[[\"ds\",\"http://www.w3.org/2000/09/xmldsig#\"]],\"NamespacePrefix\":\"ds\",\"QualifiedName\":\"ds:X509Certificate\",\"NamespaceURI\":\"http://www.w3.org/2000/09/xmldsig#\",\"Children\":[\"MIIDkDCCAvmgAwIBAgIJAO+Fcd4yj0h/MA0GCSqGSIb3DQEBBQUAMIGNMQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNU2FuIEZyYW5jaXNjbzEPMA0GA1UEChMGeG1sZGFwMScwJQYDVQQLFB5DaHVjayBNb3J0aW1vcmUgJiBBeGVsIE5lbm5rZXIxFzAVBgNVBAMTDnd3dy54bWxkYXAub3JnMB4XDTA3MDgxODIxMTIzMVoXDTE3MDgxNTIxMTIzMVowgY0xCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1TYW4gRnJhbmNpc2NvMQ8wDQYDVQQKEwZ4bWxkYXAxJzAlBgNVBAsUHkNodWNrIE1vcnRpbW9yZSAmIEF4ZWwgTmVubmtlcjEXMBUGA1UEAxMOd3d3LnhtbGRhcC5vcmcwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAOKUn6/QqTZj/BWoQVxNFI0Z2AXI1azws+RyuJek60NiawQrFAKk0Ph+/YnUiQAnzbsT+juZV08UpaPa2IE3g0+RFZtODlqoGGGakSOd9NNnDuNhsdtXJWgQq8paM9Sc4nUue31iq7LvmjSGSL5w84NglT48AcqVGr+/5vy8CfT/AgMBAAGjgfUwgfIwHQYDVR0OBBYEFGcwQKLQtW8/Dql5t70BfXX66dmaMIHCBgNVHSMEgbowgbeAFGcwQKLQtW8/Dql5t70BfXX66dmaoYGTpIGQMIGNMQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNU2FuIEZyYW5jaXNjbzEPMA0GA1UEChMGeG1sZGFwMScwJQYDVQQLFB5DaHVjayBNb3J0aW1vcmUgJiBBeGVsIE5lbm5rZXIxFzAVBgNVBAMTDnd3dy54bWxkYXAub3JnggkA74Vx3jKPSH8wDAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQUFAAOBgQAYQisGgrg1xw0TTgIZcz3JXr+ZtwjeKqEewoxCxBz1uki7hJYHIznEZq4fzSMtcBMgbKmOTzFNV0Yr/tnJ9rrljRf8EXci62ffzj+Kkny7JtM6Ltxq0BJuF3jrXogdbsc5J3W9uJ7C2+uJTHG1mApbOdJGvLAGLCaNw5NpP7+ZXQ==\"],\"LocalName\":\"X509Certificate\"}],\"LocalName\":\"X509Data\"}],\"LocalName\":\"KeyInfo\"}],\"LocalName\":\"Identity\"}],\"LocalName\":\"EndpointReference\"},{\"NamespaceDeclarations\":[[\"ic\",\"http://schemas.xmlsoap.org/ws/2005/05/identity\"]],\"NamespacePrefix\":\"ic\",\"QualifiedName\":\"ic:UserCredential\",\"NamespaceURI\":\"http://schemas.xmlsoap.org/ws/2005/05/identity\",\"Children\":[{\"NamespaceDeclarations\":[[\"ic\",\"http://schemas.xmlsoap.org/ws/2005/05/identity\"]],\"NamespacePrefix\":\"ic\",\"QualifiedName\":\"ic:DisplayCredentialHint\",\"NamespaceURI\":\"http://schemas.xmlsoap.org/ws/2005/05/identity\",\"Children\":[\"Please enter your username and password.\"],\"LocalName\":\"DisplayCredentialHint\"},{\"NamespaceDeclarations\":[[\"ic\",\"http://schemas.xmlsoap.org/ws/2005/05/identity\"]],\"NamespacePrefix\":\"ic\",\"QualifiedName\":\"ic:UsernamePasswordCredential\",\"NamespaceURI\":\"http://schemas.xmlsoap.org/ws/2005/05/identity\",\"Children\":[{\"NamespaceDeclarations\":[[\"ic\",\"http://schemas.xmlsoap.org/ws/2005/05/identity\"]],\"NamespacePrefix\":\"ic\",\"QualifiedName\":\"ic:Username\",\"NamespaceURI\":\"http://schemas.xmlsoap.org/ws/2005/05/identity\",\"Children\":[\"username\"],\"LocalName\":\"Username\"}],\"LocalName\":\"UsernamePasswordCredential\"}],\"LocalName\":\"UserCredential\"}],\"LocalName\":\"TokenService\"}],\"LocalName\":\"TokenServiceList\"},{\"NamespaceDeclarations\":[[\"ic\",\"http://schemas.xmlsoap.org/ws/2005/05/identity\"]],\"NamespacePrefix\":\"ic\",\"QualifiedName\":\"ic:SupportedTokenTypeList\",\"NamespaceURI\":\"http://schemas.xmlsoap.org/ws/2005/05/identity\",\"Children\":[{\"NamespaceDeclarations\":[[\"wst\",\"http://schemas.xmlsoap.org/ws/2005/02/trust\"]],\"NamespacePrefix\":\"wst\",\"QualifiedName\":\"wst:TokenType\",\"NamespaceURI\":\"http://schemas.xmlsoap.org/ws/2005/02/trust\",\"Children\":[\"urn:oasis:names:tc:SAML:1.0:assertion\"],\"LocalName\":\"TokenType\"}],\"LocalName\":\"SupportedTokenTypeList\"},{\"NamespaceDeclarations\":[[\"ic\",\"http://schemas.xmlsoap.org/ws/2005/05/identity\"]],\"NamespacePrefix\":\"ic\",\"QualifiedName\":\"ic:SupportedClaimTypeList\",\"NamespaceURI\":\"http://schemas.xmlsoap.org/ws/2005/05/identity\",\"Children\":[{\"NamespaceDeclarations\":[[\"ic\",\"http://schemas.xmlsoap.org/ws/2005/05/identity\"]],\"NamespacePrefix\":\"ic\",\"Attributes\":[{\"NamespacePrefix\":\"\",\"Value\":\"uri\",\"QualifiedName\":\"Uri\",\"NamespaceURI\":\"\",\"LocalName\":\"Uri\"}],\"QualifiedName\":\"ic:SupportedClaimType\",\"NamespaceURI\":\"http://schemas.xmlsoap.org/ws/2005/05/identity\",\"Children\":[{\"NamespaceDeclarations\":[[\"ic\",\"http://schemas.xmlsoap.org/ws/2005/05/identity\"]],\"NamespacePrefix\":\"ic\",\"QualifiedName\":\"ic:DisplayTag\",\"NamespaceURI\":\"http://schemas.xmlsoap.org/ws/2005/05/identity\",\"Children\":[\"displayName\"],\"LocalName\":\"DisplayTag\"},{\"NamespaceDeclarations\":[[\"ic\",\"http://schemas.xmlsoap.org/ws/2005/05/identity\"]],\"NamespacePrefix\":\"ic\",\"QualifiedName\":\"ic:Description\",\"NamespaceURI\":\"http://schemas.xmlsoap.org/ws/2005/05/identity\",\"Children\":[\"description\"],\"LocalName\":\"Description\"}],\"LocalName\":\"SupportedClaimType\"}],\"LocalName\":\"SupportedClaimTypeList\"},{\"NamespaceDeclarations\":[[\"ic\",\"http://schemas.xmlsoap.org/ws/2005/05/identity\"]],\"NamespacePrefix\":\"ic\",\"Attributes\":[{\"NamespacePrefix\":\"\",\"Value\":\"1\",\"QualifiedName\":\"Version\",\"NamespaceURI\":\"\",\"LocalName\":\"Version\"}],\"QualifiedName\":\"ic:PrivacyNotice\",\"NamespaceURI\":\"http://schemas.xmlsoap.org/ws/2005/05/identity\",\"Children\":[\"privacyPolicyUrl\"],\"LocalName\":\"PrivacyNotice\"},{\"NamespaceDeclarations\":[[\"ic07\",\"http://schemas.xmlsoap.org/ws/2007/01/identity\"]],\"NamespacePrefix\":\"ic07\",\"QualifiedName\":\"ic07:RequireStrongRecipientIdentity\",\"NamespaceURI\":\"http://schemas.xmlsoap.org/ws/2007/01/identity\",\"LocalName\":\"RequireStrongRecipientIdentity\"}],\"LocalName\":\"InformationCard\"}";
    assertEquals(expected, json.toString());
  }

//  public void testParsedInfocardToJSON() throws Exception {
//    String bceidCardStr = "<i:InformationCard xml:lang=\"en\" xmlns:i=\"http://schemas.xmlsoap.org/ws/2005/05/identity\"><i:InformationCardReference><i:CardId>urn:GUID:6d6693c1-6b1a-df11-b009-00143851d232</i:CardId><i:CardVersion>4</i:CardVersion></i:InformationCardReference><i:CardName>BCeID Information Card</i:CardName><i:CardImage MimeType=\"image/jpeg\">/9j/4AAQSkZJRgABAQEAeAB4AAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCABQAHgDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVp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Yhc+nTFKnKNRNxewSTi0mdtRXBrea9cfEW60D+3JIrOO0F0rJbRb+SBtyVIxyea1NUj8T6Rave2F/HqixDc9rcwqjuo67WQAZ+orTk1tcnmOoorJ8N+ILTxNo0WpWmVVsq8bdY3HVTWtUtNOzKTuFFFFIAooooAxPGL+X4K1w4zmxmH5oR/WuQt/Dmr6x8OdNjttZYobSN/sckSiOUAZCFlw2O3Wu18S6dc6v4cv9OtHiSa5iMQaXO0A8Hp7ZrH0nSvFGm+HYNIE+lqYYvKW6BdmA6A7MAEj61rCVo/MiSuzgte8QLrnhPwvqL2q21raamsN1Cg+RCoGMe23P8q9pBBAIOQa5uy8EaVbeEW8OzK09vJlpZG4ZnPO/2PTH0pmlaf4k0G3SxSa01SziG2F53aGZV7AkBg2PXinNxkrLoKKa3OnZgqkngCuXtGutY1GW+SONo4iUh8xvlT3wOpqePTdZ1DWYrzVJbaG0gRxFaWzM5LsNu5mIGcAnAA707TtM1XTlkt4prfyWbIdgSw/CvMxcJOcFq49bdzqoySjJ9S/aaUIrs3lxKZ7kjAYjAUegFct4B/5GHxh/2Ej/AFrshHNBZlIWE0wBKmZiAze5AOB9BXMeFvD2taJrGq3V3JYSw6lcGdxE7hozzwMrz1HpXZQhGFNpaXMZtykmVLT/AJLVf/8AYJX/ANDWu5JAUk8Ada4dvDviaPxvJ4kgfS/ngFu1s0kmCnB+9t65HpWvf2Gv6zbNZz3Fpp1tKNsrWrNLKynqAzBQufXBraVnbUhXVznPhKh+x67PGCLSXUHMPoQPT9K9FqnpemWmjabDYWMQit4Vwqj+Z9SauVE5c0myoqysFFFFSMKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigD//Z</i:CardImage><i:Issuer>http://stsip.systestv2.bceid.ca/adfs/services/trust</i:Issuer><i:TimeIssued>2010-04-15T17:52:07.341Z</i:TimeIssued><i:TokenServiceList><i:TokenService><EndpointReference xmlns=\"http://www.w3.org/2005/08/addressing\"><Address>https://stsip.systestv2.bceid.ca/adfs/services/trust/2005/usernamemixed</Address><Metadata><Metadata xmlns=\"http://schemas.xmlsoap.org/ws/2004/09/mex\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:wsx=\"http://schemas.xmlsoap.org/ws/2004/09/mex\"><wsx:MetadataSection Dialect=\"http://schemas.xmlsoap.org/ws/2004/09/mex\" xmlns=\"\"><wsx:MetadataReference><Address xmlns=\"http://www.w3.org/2005/08/addressing\">https://stsip.systestv2.bceid.ca/adfs/services/trust/mex</Address></wsx:MetadataReference></wsx:MetadataSection></Metadata></Metadata></EndpointReference><i:UserCredential><i:UsernamePasswordCredential><i:Username>SBCEID\\pwiebe10i</i:Username></i:UsernamePasswordCredential></i:UserCredential></i:TokenService><i:TokenService><EndpointReference xmlns=\"http://www.w3.org/2005/08/addressing\"><Address>https://stsip.systestv2.bceid.ca/adfs/services/trust/13/usernamemixed</Address><Metadata><Metadata xmlns=\"http://schemas.xmlsoap.org/ws/2004/09/mex\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:wsx=\"http://schemas.xmlsoap.org/ws/2004/09/mex\"><wsx:MetadataSection Dialect=\"http://schemas.xmlsoap.org/ws/2004/09/mex\" xmlns=\"\"><wsx:MetadataReference><Address xmlns=\"http://www.w3.org/2005/08/addressing\">https://stsip.systestv2.bceid.ca/adfs/services/trust/mex</Address></wsx:MetadataReference></wsx:MetadataSection></Metadata></Metadata></EndpointReference><i:UserCredential><i:UsernamePasswordCredential><i:Username>SBCEID\\pwiebe10i</i:Username></i:UsernamePasswordCredential></i:UserCredential></i:TokenService></i:TokenServiceList><i:SupportedTokenTypeList><t:TokenType xmlns:t=\"http://schemas.xmlsoap.org/ws/2005/02/trust\">urn:oasis:names:tc:SAML:1.0:assertion</t:TokenType><t:TokenType xmlns:t=\"http://schemas.xmlsoap.org/ws/2005/02/trust\">http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV1.1</t:TokenType><t:TokenType xmlns:t=\"http://schemas.xmlsoap.org/ws/2005/02/trust\">http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV2.0</t:TokenType></i:SupportedTokenTypeList><i:SupportedClaimTypeList><i:SupportedClaimType Uri=\"http://idmanagement.gov/icam/2009/09/imi_1.0_profile#assurancelevel1\"><i:DisplayTag>ICAM Assurance Level 1</i:DisplayTag><i:Description>Level of Assurance achieved according to the rules of the ICAM IMI 1.0 profile located at http://www.idmanagement.gov/</i:Description></i:SupportedClaimType><i:SupportedClaimType Uri=\"http://www.cio.gov.bc.ca/standards/claims/2009/11/useridentifier\"><i:DisplayTag>User Identifier</i:DisplayTag></i:SupportedClaimType><i:SupportedClaimType Uri=\"http://www.ocio.gov.bc.ca/standards/claims/2009/06/userdisplayname\"><i:DisplayTag>User Display Name</i:DisplayTag></i:SupportedClaimType><i:SupportedClaimType Uri=\"http://www.ocio.gov.bc.ca/standards/claims/2009/09/identityassurancelevel\"><i:DisplayTag>Identity Assurance Level</i:DisplayTag></i:SupportedClaimType><i:SupportedClaimType Uri=\"http://www.ocio.gov.bc.ca/standards/claims/2009/09/authoritativepartyidentifier\"><i:DisplayTag>AP Identifier</i:DisplayTag></i:SupportedClaimType><i:SupportedClaimType Uri=\"http://www.ocio.gov.bc.ca/standards/claims/2009/09/authoritativepartyname\"><i:DisplayTag>AP Name</i:DisplayTag></i:SupportedClaimType><i:SupportedClaimType Uri=\"http://www.cio.gov.bc.ca/standards/claims/2009/09/identityassurancelevel1\"><i:DisplayTag>Identity Assurance Level 1</i:DisplayTag></i:SupportedClaimType><i:SupportedClaimType Uri=\"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress\"><i:DisplayTag>E-Mail Address</i:DisplayTag><i:Description>The e-mail address of the user</i:Description></i:SupportedClaimType><i:SupportedClaimType Uri=\"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname\"><i:DisplayTag>Given Name</i:DisplayTag><i:Description>The given name of the user</i:Description></i:SupportedClaimType><i:SupportedClaimType Uri=\"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name\"><i:DisplayTag>Name</i:DisplayTag><i:Description>The unique name of the user</i:Description></i:SupportedClaimType><i:SupportedClaimType Uri=\"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/upn\"><i:DisplayTag>UPN</i:DisplayTag><i:Description>The user principal name (UPN) of the user</i:Description></i:SupportedClaimType><i:SupportedClaimType Uri=\"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname\"><i:DisplayTag>Surname</i:DisplayTag><i:Description>The surname of the user</i:Description></i:SupportedClaimType><i:SupportedClaimType Uri=\"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/privatepersonalidentifier\"><i:DisplayTag>PPID</i:DisplayTag><i:Description>The private identifier of the user</i:Description></i:SupportedClaimType><i:SupportedClaimType Uri=\"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier\"><i:DisplayTag>Name ID</i:DisplayTag><i:Description>The SAML name identifier of the user</i:Description></i:SupportedClaimType><i:SupportedClaimType Uri=\"http://schemas.microsoft.com/ws/2008/06/identity/claims/authenticationinstant\"><i:DisplayTag>Authentication time stamp</i:DisplayTag><i:Description>Used to display the time and date that the user was authenticated</i:Description></i:SupportedClaimType><i:SupportedClaimType Uri=\"http://schemas.microsoft.com/ws/2008/06/identity/claims/authenticationmethod\"><i:DisplayTag>Authentication method</i:DisplayTag><i:Description>The method used to authenticate the user</i:Description></i:SupportedClaimType></i:SupportedClaimTypeList><i:RequireAppliesTo Optional=\"false\"></i:RequireAppliesTo><ic09:IssuerName xmlns:ic09=\"http://docs.oasis-open.org/imi/ns/identity-200903\">stsip.systestv2.bceid.ca</ic09:IssuerName><ic09:CardType xmlns:ic09=\"http://docs.oasis-open.org/imi/ns/identity-200903\">urn:GUID:6d6693c1-6b1a-df11-b009-00143851d232</ic09:CardType></i:InformationCard>";
//    Document doc = XmlUtils.parse(bceidCardStr);
//    
//    InfoCard card = new InfoCard(doc.getRootElement());
//    JSONObject json = card.toJSON();
//    String expected = "{\"SupportedTokenTypeList\":[\"http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV2.0\"],\"CardImages\":[{\"base64BinaryCardImage\":\"/9j/4AAQSkZJRgABAQEAeAB4AAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCABQAHgDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwD340ZNBrg/FXxAGi301lbwGR4xhmCbhn9Py9qyrVoUo80jCviKdCPNUZr6l470TSbyO3u7pU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ckSiOUAZCFlw2O3Wu18S6dc6v4cv9OtHiSa5iMQaXO0A8Hp7ZrH0nSvFGm+HYNIE+lqYYvKW6BdmA6A7MAEj61rCVo/MiSuzgte8QLrnhPwvqL2q21raamsN1Cg+RCoGMe23P8q9pBBAIOQa5uy8EaVbeEW8OzK09vJlpZG4ZnPO/2PTH0pmlaf4k0G3SxSa01SziG2F53aGZV7AkBg2PXinNxkrLoKKa3OnZgqkngCuXtGutY1GW+SONo4iUh8xvlT3wOpqePTdZ1DWYrzVJbaG0gRxFaWzM5LsNu5mIGcAnAA707TtM1XTlkt4prfyWbIdgSw/CvMxcJOcFq49bdzqoySjJ9S/aaUIrs3lxKZ7kjAYjAUegFct4B/5GHxh/2Ej/AFrshHNBZlIWE0wBKmZiAze5AOB9BXMeFvD2taJrGq3V3JYSw6lcGdxE7hozzwMrz1HpXZQhGFNpaXMZtykmVLT/AJLVf/8AYJX/ANDWu5JAUk8Ada4dvDviaPxvJ4kgfS/ngFu1s0kmCnB+9t65HpWvf2Gv6zbNZz3Fpp1tKNsrWrNLKynqAzBQufXBraVnbUhXVznPhKh+x67PGCLSXUHMPoQPT9K9FqnpemWmjabDYWMQit4Vwqj+Z9SauVE5c0myoqysFFFFSMKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigD//Z\",\"mimeType\":\"image/jpeg\"}],\"CardId\":\"urn:GUID:6d6693c1-6b1a-df11-b009-00143851d232\",\"Issuer\":\"http://stsip.systestv2.bceid.ca/adfs/services/trust\",\"IssuerName\":\"stsip.systestv2.bceid.ca\",\"SupportedClaimTypeList\":[{\"Description\":\"Level of Assurance achieved according to the rules of the ICAM IMI 1.0 profile located at http://www.idmanagement.gov/\",\"Uri\":\"http://idmanagement.gov/icam/2009/09/imi_1.0_profile#assurancelevel1\",\"DisplayTag\":\"ICAM Assurance Level 1\"},{\"Uri\":\"http://www.cio.gov.bc.ca/standards/claims/2009/11/useridentifier\",\"DisplayTag\":\"User Identifier\"},{\"Uri\":\"http://www.ocio.gov.bc.ca/standards/claims/2009/06/userdisplayname\",\"DisplayTag\":\"User Display Name\"},{\"Uri\":\"http://www.ocio.gov.bc.ca/standards/claims/2009/09/identityassurancelevel\",\"DisplayTag\":\"Identity Assurance Level\"},{\"Uri\":\"http://www.ocio.gov.bc.ca/standards/claims/2009/09/authoritativepartyidentifier\",\"DisplayTag\":\"AP Identifier\"},{\"Uri\":\"http://www.ocio.gov.bc.ca/standards/claims/2009/09/authoritativepartyname\",\"DisplayTag\":\"AP Name\"},{\"Uri\":\"http://www.cio.gov.bc.ca/standards/claims/2009/09/identityassurancelevel1\",\"DisplayTag\":\"Identity Assurance Level 1\"},{\"Description\":\"The e-mail address of the user\",\"Uri\":\"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress\",\"DisplayTag\":\"E-Mail Address\"},{\"Description\":\"The given name of the user\",\"Uri\":\"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname\",\"DisplayTag\":\"Given Name\"},{\"Description\":\"The unique name of the user\",\"Uri\":\"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name\",\"DisplayTag\":\"Name\"},{\"Description\":\"The user principal name (UPN) of the user\",\"Uri\":\"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/upn\",\"DisplayTag\":\"UPN\"},{\"Description\":\"The surname of the user\",\"Uri\":\"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname\",\"DisplayTag\":\"Surname\"},{\"Description\":\"The private identifier of the user\",\"Uri\":\"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/privatepersonalidentifier\",\"DisplayTag\":\"PPID\"},{\"Description\":\"The SAML name identifier of the user\",\"Uri\":\"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier\",\"DisplayTag\":\"Name ID\"},{\"Description\":\"Used to display the time and date that the user was authenticated\",\"Uri\":\"http://schemas.microsoft.com/ws/2008/06/identity/claims/authenticationinstant\",\"DisplayTag\":\"Authentication time stamp\"},{\"Description\":\"The method used to authenticate the user\",\"Uri\":\"http://schemas.microsoft.com/ws/2008/06/identity/claims/authenticationmethod\",\"DisplayTag\":\"Authentication method\"}],\"CardVersion\":4,\"ExtraElements\":[{\"NamespaceDeclarations\":[[\"ic09\",\"http://docs.oasis-open.org/imi/ns/identity-200903\"]],\"NamespacePrefix\":\"ic09\",\"QualifiedName\":\"ic09:CardType\",\"NamespaceURI\":\"http://docs.oasis-open.org/imi/ns/identity-200903\",\"Children\":[\"urn:GUID:6d6693c1-6b1a-df11-b009-00143851d232\"],\"LocalName\":\"CardType\"}],\"TimeIssued\":\"2010-04-15T17:52:07.341Z\",\"CardName\":\"BCeID Information Card\",\"RequireAppliesTo\":false,\"TokenServiceList\":[{\"UserCredential\":{\"Type\":\"UserNamePasswordAuthenticate\",\"Username\":\"SBCEID\\pwiebe10i\"},\"EndpointReference\":{\"STS\":\"https://stsip.systestv2.bceid.ca/adfs/services/trust/mex\",\"Mex\":\"https://stsip.systestv2.bceid.ca/adfs/services/trust/mex\"}},{\"UserCredential\":{\"Type\":\"UserNamePasswordAuthenticate\",\"Username\":\"SBCEID\\pwiebe10i\"},\"EndpointReference\":{\"STS\":\"https://stsip.systestv2.bceid.ca/adfs/services/trust/mex\",\"Mex\":\"https://stsip.systestv2.bceid.ca/adfs/services/trust/mex\"}}]}";
//    assertEquals(expected, json.toString());
//  }
}
